# C语言指针学习教程 Makefile

CC = gcc
CFLAGS = -Wall -Wextra -std=c99
TARGETS = lesson1 lesson2 lesson3 lesson4 lesson5 lesson6

# 默认目标
all: $(TARGETS)

# 各个课程的编译规则
lesson1: main.c
	$(CC) $(CFLAGS) -o $@ $<

lesson2: lesson2_pointer_operations.c
	$(CC) $(CFLAGS) -o $@ $<

lesson3: lesson3_pointer_functions.c
	$(CC) $(CFLAGS) -o $@ $<

lesson4: lesson4_pointer_arrays.c
	$(CC) $(CFLAGS) -o $@ $<

lesson5: lesson5_dynamic_memory.c
	$(CC) $(CFLAGS) -o $@ $<

lesson6: lesson6_advanced_pointers.c
	$(CC) $(CFLAGS) -o $@ $<

# 运行所有课程
run-all: all
	@echo "=== 运行所有C语言指针学习课程 ==="
	@echo
	./lesson1
	@echo
	./lesson2
	@echo
	./lesson3
	@echo
	./lesson4
	@echo
	./lesson5
	@echo
	./lesson6

# 运行单个课程
run-lesson1: lesson1
	./lesson1

run-lesson2: lesson2
	./lesson2

run-lesson3: lesson3
	./lesson3

run-lesson4: lesson4
	./lesson4

run-lesson5: lesson5
	./lesson5

run-lesson6: lesson6
	./lesson6

# 清理编译文件
clean:
	rm -f $(TARGETS)

# 深度清理（包括临时文件）
clean-all: clean
	rm -f *.o *.out *.dSYM

# 帮助信息
help:
	@echo "C语言指针学习教程 - 可用命令："
	@echo "  make all        - 编译所有课程"
	@echo "  make lesson1    - 编译第一课"
	@echo "  make lesson2    - 编译第二课"
	@echo "  make lesson3    - 编译第三课"
	@echo "  make lesson4    - 编译第四课"
	@echo "  make lesson5    - 编译第五课"
	@echo "  make lesson6    - 编译第六课"
	@echo "  make run-all    - 编译并运行所有课程"
	@echo "  make run-lesson1 - 编译并运行第一课"
	@echo "  make run-lesson2 - 编译并运行第二课"
	@echo "  make run-lesson3 - 编译并运行第三课"
	@echo "  make run-lesson4 - 编译并运行第四课"
	@echo "  make run-lesson5 - 编译并运行第五课"
	@echo "  make run-lesson6 - 编译并运行第六课"
	@echo "  make clean      - 清理编译文件"
	@echo "  make clean-all  - 深度清理"
	@echo "  make help       - 显示此帮助信息"

# 声明伪目标
.PHONY: all run-all run-lesson1 run-lesson2 run-lesson3 run-lesson4 run-lesson5 run-lesson6 clean clean-all help 